package com.diandiansong.manager.ui.user;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.diandiansong.app.R;
import com.diandiansong.app.ui.user.About;
import com.diandiansong.manager.entity.SalesLoginInfo;
import com.diandiansong.manager.ui.Main;

import butterknife.BindView;
import butterknife.OnClick;
import diandiansong.library.ui.base.BaseAct;

/**
 * 系统设置
 */
public class SystemSetting extends BaseAct {
    public static void start(Context context) {
        Intent starter = new Intent(context, SystemSetting.class);
        context.startActivity(starter);
    }

    @BindView(R.id.tv_version)
    TextView mTvVersion;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addContentView(R.layout.system_setting);
        initTitle("系统设置");

        mTvVersion.setText(getVersionName());
    }

    @OnClick({R.id.go_pwd, R.id.go_about, R.id.go_version, R.id.do_logout})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.go_pwd:
                ForgetPwd.start(getActivity());
                break;
            case R.id.go_about:
                About.start(getActivity());
                break;
            case R.id.go_version:
                toast("已经是最新版本");
                break;
            case R.id.do_logout:
                SalesLoginInfo.clearSalesLoginInfo(getActivity());
                Login.start(getActivity());
                Main.doFinish();
                finish();
                break;
        }
    }

    public String getVersionName() {
        PackageInfo pInfo = null;
        try {
            pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
            return pInfo.versionName;

        } catch (PackageManager.NameNotFoundException e) {
            throw new RuntimeException("Could not get package version name: " + e);
        }
    }
}
